package com.hm.recycle.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hm.common.annotation.AuthenticationAnnotation;
import com.hm.common.annotation.RequestPlanAnnotation;
import com.hm.common.model.ControllerResult;
import com.hm.common.model.PageInfo;
import com.hm.common.util.DbDocumentDef;
import com.hm.common.util.RequestLogDef;
import com.hm.recycle.mongo.vo.UpdateRecycleVo;
import com.hm.recycle.share.service.DbDocumentUpdateRecycleService;
import com.hm.recycle.util.RecycleConfigDef.Api.Rest;
import com.hm.recycle.web.su.BaseController;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @author shishun.wang
 * @date 2016年6月5日 下午10:54:29
 * @version 1.0
 * @describe
 */
@ResponseBody
@RestController
@RequestMapping(value = Rest.Recycle.REST_RECYCLE_UPDATE)
public class DbDocumentUpdateRecycleController extends BaseController {

	public static final String swaggerTag = "数据更新历史日志";

	@Autowired
	private DbDocumentUpdateRecycleService dbDocumentUpdateRecycleService;

	@AuthenticationAnnotation
	@RequestMapping(value = "/{pageNumber}/{pageSize}", method = RequestMethod.GET)
	@ApiOperation(value = "获取数据更新历史日志", httpMethod = "GET", notes = "分页获取数据更新历史日志", tags = swaggerTag)
	@RequestPlanAnnotation(title = "获取数据更新历史日志", content = "分页获取数据更新历史日志")
	public ResponseEntity<ControllerResult<PageInfo<UpdateRecycleVo>>> queryUpdateRecycle(
			@ApiParam(required = true, name = "pageNumber", value = "分页号(第一页值为1,小于1则默认返回第一页)") @PathVariable("pageNumber") Integer pageNumber,
			@ApiParam(required = true, name = "pageSize", value = "分页大小") @PathVariable("pageSize") Integer pageSize,
			@ApiParam(required = false, name = "documentDef", value = "文档定义") @RequestParam(required = false) DbDocumentDef documentDef,
			@ApiParam(required = false, name = "operationUser", value = "操作人") @RequestParam(required = false) String operationUser,
			@ApiParam(required = false, name = "version", value = "版本号") @RequestParam(required = false) Integer version,
			@ApiParam(required = false, name = "startTime", value = "开始时间") @RequestParam(required = false) Long startTime,
			@ApiParam(required = false, name = "endTime", value = "结束时间") @RequestParam(required = false) Long endTime,
			@ApiParam(required = true, name = "requestLog", value = "日志类型") @RequestParam RequestLogDef requestLog) {
		try {
			return ControllerResult.success(dbDocumentUpdateRecycleService.queryUpdateRecycle(documentDef,
					operationUser, version, startTime, endTime, pageNumber, pageSize));
		} catch (Exception e) {
			return ControllerResult.failed(e);
		}
	}
}
